/*
 * Created on 2006-2-22
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package cn.com.sbell.vss.csg.vap;

import org.dom4j.Element;

import cn.com.sbell.vss.csg.vap.bean.GPIODeviceInfo;
import cn.com.sbell.vss.csg.vsclient.VsClient;
import cn.com.sbell.vss.csg.vsclient.util.PropertiesHolder;

/**
 * @author liang.a.chen
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class GetVsInOutDev extends ProtectedVsCommander {

	protected Element executeCommand(VsClient vsClient, PropertiesHolder holder, Element root) {
		GPIODeviceInfo devInfo = vsClient.getInOutDev();
		GPIODeviceInfo.ChannelInfo[] channelInfo = devInfo.getInput();
		for(int i=0;i<channelInfo.length;i++){
			parseToXML(root.addElement("input"), channelInfo[i]);
		}
		channelInfo = devInfo.getOutput();
		for(int i=0;i<channelInfo.length;i++){
			parseToXML(root.addElement("output"), channelInfo[i]);
		}
		return root;
	}
	
	private void parseToXML(Element element, GPIODeviceInfo.ChannelInfo channelInfo){
		element.addElement("channelNumber").addText(toString(channelInfo.getChannelNumber()));
		element.addElement("state").addText(toString(channelInfo.getState()));
	}
}
